package world.ztomorrow.push.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.concurrent.TimeUnit;

import static world.ztomorrow.push.constant.PushConstant.CAFFEINE_VISIT_RANK_TTL;


@Configuration
public class CaffeineConfig {

    @Bean
    public Cache<String, List<Object>> caffeine() {
        return Caffeine.newBuilder()
                .expireAfterAccess(CAFFEINE_VISIT_RANK_TTL, TimeUnit.MINUTES)
                .build();
    }

    @Bean
    public <T> Cache<String, T> caffeineOne() {
        return Caffeine.newBuilder()
                .expireAfterAccess(CAFFEINE_VISIT_RANK_TTL, TimeUnit.MINUTES)
                .build();
    }
}
